set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode='nonstrict';
set hive.exec.max.dynamic.partitions=400;
set hive.exec.max.dynamic.partitions.pernode=400;

insert overwrite table jms_dm.dm_taking_timely_mall_summary_dt
select
    mall_id
   ,mall_name
   ,customer_code
   ,customer_name
   ,start_network_code
   ,start_network_name
   ,start_city_code
   ,start_city_name
   ,start_province_code
   ,start_province_name
   ,start_agent_code
   ,start_agent_name
   ,count(1) as all_cnt
   ,count(case when taking_time is not null then waybill_no end) as taking_cnt
   ,count(case when if_tml_collect = 0 then waybill_no end) as js_cnt
   ,count(case when if_tml_collect = 1 then waybill_no end) as bjs_cnt
   ,dt
from jms_dm.dm_taking_timely_mall_detail_dt
where dt = '{{ execution_date | cst_ds }}'
group by mall_id
        ,mall_name
        ,customer_code
        ,customer_name
        ,start_network_code
        ,start_network_name
        ,start_city_code
        ,start_city_name
        ,start_province_code
        ,start_province_name
        ,start_agent_code
        ,start_agent_name
        ,dt
distribute by pmod(hash(rand()),1);